<template>
	<FormModal ref='formModalRef' :config='config'/>
</template>

<script setup>
	/* --------------------------- Component --------------------------- */
	const FormModal = $.lazy(()=>import('#cpt/temp/FormModal.vue'))
	/* --------------------------- ref --------------------------- */
	ref: formModalRef
	/* --------------------------- Event --------------------------- */
	let param = {}
	
	const emit = defineEmits(['change'])
	let upload = {}
	
	ref: config = {
		title: '上传附件',
		labelWidth:'s6',
		scroll: false,
		// footer:false,
		bodyStyle:{paddingBottom:'20px'},
		data:[
			{ label:'业务类型', name:'businessTypeId', r:1, type:'tree-select', mul:false, api:'file/businessTypeList', idStr:'businessTypeId', nameStr:'typeName', change:({value})=>{
				$fn.getRow(config, 'file').param['businessTypeId'] = value
			} },
			{ label:'附件', name:'file', type:'upload', t:'array', mode:'text', mb:0, r:1, param:{}, mul:true, my:true, list:true, change: res =>{
				upload = res
				// emit('change', data)
				// formModalRef.close()
			} }
		],
		onSubmit: param => {
			const fd = $fn.FormDataUploader(upload.fileName, upload.files, $fn.getRow(config, 'file').param)
			if(upload){
				$http.upload(null, upload.api,{ param:fd }).then( data => {
					emit('change', data)
					formModalRef.close()
				})
			}
		}
	}
	
	defineExpose({
		open: ({ targetBusinessKey }) => {
			if(targetBusinessKey){
				$fn.getRow(config, 'file').param['targetBusinessKey'] = targetBusinessKey
			}
			formModalRef.open()
		} 
	})
</script>
